home *** CD-ROM | disk | FTP | other *** search
- # include "TransSkel.h"
-
- # include "MWMaca.h"
- # include "MakeWrite.h"
-
-
- /*
- * markRes holds the result, for each map line, of the current match
- * state. Element i is true if mark i still matches the input, false
- * if not.
- *
- * markRes is big enough to hold one entry for each formatting
- * specification, plus one entry for each special marker. The special
- * marks must generally be special-cased.
- *
- * Right now there's two special marks - the paragraph indicator
- * mark and the page break.
- *
- * markPos is the position in the marks that the current input char is
- * matched against.
- */
-
- # define maxMarkers (maxMappings + extraMarks)
-
-
- static Boolean markRes[maxMarkers];
- static short markPos;
-
-
- /*
- * Look for marks that are empty. This is done before any text->write
- * conversion because empty marks are illegal.
- *
- * Return false if no empty marks, otherwise true.
- *
- * No check on the paragraph marker: that's handled by the paragraph
- * style dialog.
- */
-
- Boolean
- FindEmptyMark (void)
- {
- short i;
-
- for (i = 0; i < mapList->nLines; ++i)
- {
- if ((*mapSpec[i].mark)[0] == 0)
- {
- SelectMapping (i);
- Message1 ("\pCan't have empty format markers");
- return (true);
- }
- }
- return (false);
- }
-
-
- /*
- * Initialize all the used mark states (every mark eligible) and
- * reset the mark position
- */
-
- void
- InitMarkStates (void)
- {
- short i;
-
- markPos = 0;
- for (i = 0; i < mapList->nLines; ++i)
- markRes[i] = true;
- for (i = maxMappings; i < maxMarkers; ++i)
- markRes[i] = true;
- }
-
-
- /*
- * Check current input character against the current mark position
- * of each of the marks that are still in the running for a match.
- * Eliminate those that don't match the char. For those that do,
- * if the entire mark has been matched, then it's a hit, and the format
- * of the input should be changed to that of the format corresponding
- * to the mark.
- *
- * Return -2 if no more marks are in the running, -1 if any marks
- * are still in the running but none have been matched completely,
- * otherwise return the index of the completely matched mark.
- *
- * Check format markers first, then paragraph marker (if one is being
- * used).
- */
-
- short
- CheckMarkers (char c)
- {
- short i;
- short count = 0; /* number of matches */
- StringHandle hStr;
-
- ++markPos; /* advance to next marker position */
- for (i = 0; i < mapList->nLines; ++i)
- {
- if (markRes[i]) /* if mark still in running */
- {
- hStr = mapSpec[i].mark;
- if (c != (*hStr)[markPos])
- markRes[i] = false; /* this one's eliminated now */
- else
- { /* this one still matches -- */
- ++count; /* has the end been reached? */
- if (markPos == (*hStr)[0])
- return (i); /* yes */
- }
- }
- }
-
- /*
- * Check special marks: paragraph and page break
- */
- if (paraMark[0] > 0 && markRes[paraMarkIdx])
- {
- if (c != paraMark[markPos])
- markRes[paraMarkIdx] = false;
- else
- {
- ++count;
- if (markPos == paraMark[0])
- return (paraMarkIdx);
- }
- }
-
- if (pageMark[0] > 0 && markRes[pageMarkIdx])
- {
- if (c != pageMark[markPos])
- markRes[pageMarkIdx] = false;
- else
- {
- ++count;
- if (markPos == paraMark[0])
- return (pageMarkIdx);
- }
- }
-
- return (count > 0 ? -1 : -2);
- }
-
-
- /*
- * Check two markers. If one is a prefix of the other, put up a
- * warning. Return false if the user says not to continue. If the
- * user says to continue, or there's no conflict, return true.
- */
-
- static Boolean
- ConflictCheck (StringPtr s1, StringPtr s2,
- StringPtr type1, StringPtr type2)
- {
- short i, len;
-
- len = s1[0];
- if (s2[0] < len)
- len = s2[0];
- for (i = 1; i <= len; ++i)
- {
- if (s1[i] != s2[i])
- return (true); /* not a prefix - continue */
- }
- ParamText (type1, s1, type2, s2);
- i = SkelAlert (conflictAlrtNum, SkelDlogFilter (nil, true),
- skelPositionOnParentWindow);
- SkelRmveDlogFilter ();
- return (i == 1);
- }
-
-
- /*
- * Find conflicts among the set of markers
- */
-
- void
- FindConflicts (void)
- {
- short i, j;
- StringHandle h1, h2;
- Boolean loop = true;
-
- for (i = 0; loop && i < mapList->nLines; ++i)
- {
- h1 = mapSpec[i].mark;
- HLock ((Handle) h1);
- for (j = i + 1; loop && j < mapList->nLines; ++j)
- {
- h2 = mapSpec[j].mark;
- HLock ((Handle) h2);
- loop = ConflictCheck (*h1, *h2, "\pformat", "\pformat");
- HUnlock ((Handle) h2);
- }
- if (loop && paraMark[0] > 0)
- loop = ConflictCheck (*h1, paraMark, "\pformat", "\pparagraph");
- if (loop && pageMark[0] > 0)
- loop = ConflictCheck (*h1, pageMark, "\pformat", "\ppage break");
- if (loop && paraMark[0] > 0 && pageMark[0] > 0)
- loop = ConflictCheck (paraMark, pageMark, "\pparagraph", "\ppage break");
- HUnlock ((Handle) h1);
- }
- }